<?php 
/*
 module:		公司表
 create_time:	2024-03-14 09:29:04
 author:		
 contact:		
*/

namespace app\api\controller;

use app\api\service\CompanyprofileService;
use app\api\model\Companyprofile as CompanyprofileModel;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;

class Companyprofile extends Common {




 /*start*/
    /**
     * @api {get} /Companyprofile/index 01、首页数据列表
     */
    function index()
    {
        $limit = $this->request->get('limit', 20, 'intval');
        $page = $this->request->get('page', 1, 'intval');
        $companyname = $this->request->get('companyname', "");
        $where = [];
        if (!empty($companyname)) {
            $where['companyname'] = ['like', $companyname];
        }

        $field = 'id,companyname,company_num,nature_cn,trade_cn,district_cn,
		street_cn,scale_cn,registered,currency,address,contact,telephone,landline_tel,email,website,
	    logo,map_x,map_y,addtime,refreshtime,click,comment,resume_processing,tag,qq,short_name,lng,lat';
        $orderby = 'id desc';

        $res = CompanyprofileService::indexList(formatWhere($where), $field, $orderby, $limit, $page);
        if (!empty($res["list"])) {
            $list = $res["list"];
            foreach ($list as &$item) {
                $item = $this->getItem($item);
            }
            $res["list"] = $list;
        }
        return $this->ajaxReturn($this->successCode, '返回成功',$res);
    }

    /**
     * @api {get} /Companyprofile/view 02、查看详情
     */
    function view()
    {
        $data['id'] = $this->request->get('company_id', '', 'serach_in');
        $field = 'id,companyname,company_num,nature_cn,trade_cn,district_cn,
		street_cn,scale_cn,registered,currency,address,contact,telephone,landline_tel,email,website,
	    logo,contents,map_x,map_y,addtime,refreshtime,click,comment,resume_processing,tag,qq,short_name,lng,lat';
        $res = CompanyprofileModel::field($field)->where($data)->findOrEmpty()->toArray();
        $res = $this->getItem($res);
        $uid = $this->request->uid;
        $res["is_collection"] = 0;
        if (!empty($uid)) {
            $where = [];
            $where['company_id'] = $data['id'];
            $where['uid'] = $uid;
            $info = \app\api\model\Personalfocuscompany::where($where)->findOrEmpty()->toArray();
            if (!empty($info)) {
                $res["is_collection"] = 1;
            }
        }
        return $this->ajaxReturn($this->successCode, '返回成功', $res);
    }
    /**
     * @api {get} /Companyprofile/noLoginView 03、不登录详情
     */
    function noLoginView(){
        $data['id'] = $this->request->get('company_id', '', 'serach_in');
        $field = 'id,companyname,company_num,nature_cn,trade_cn,district_cn,
		street_cn,scale_cn,registered,currency,address,contact,telephone,landline_tel,email,website,
	    logo,contents,map_x,map_y,addtime,refreshtime,click,comment,resume_processing,tag,qq,short_name,lng,lat';
        $res = CompanyprofileModel::field($field)->where($data)->findOrEmpty()->toArray();
        $res = $this->getItem($res);
        $res["is_collection"] = 0;
        return $this->ajaxReturn($this->successCode, '返回成功', $res);
    }
    public function getItem($item)
    {
        $item["refreshtime"] = timeAnalysis2($item["refreshtime"]);
        if (empty($item["tag"]) || $item["tag"] == "请选择") {
            $item["tag"] = [];
        } else {
            $item["tag"] = explode(",", $item["tag"]);
        }
        if (!empty($item["contents"])) {
            $item["contents"] = htmlspecialchars_decode($item["contents"]);
        }
        if (!empty($item["logo"])) {
            $item["logo"] = "https://www.lianhezhaopin.com/data/upload/company_logo/" . $item["logo"];
        }
        return $item;
    }
    /*end*/



}

